package com.chixing.service.impl;

import com.chixing.mapper.CustomerMapper;
import com.chixing.mapper.MyOrderMapper;
import com.chixing.mapper.StoreMapper;
import com.chixing.pojo.Customer;
import com.chixing.pojo.MyOrder;
import com.chixing.pojo.Store;
import com.chixing.pojo.StoreExample;
import com.chixing.service.StoreService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.SqlReturnResultSet;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StoreServiceImpl implements StoreService {
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private MyOrderMapper myOrderMapper;
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public ServerResponse getAll() {
        List<Store> storeList = storeMapper.selectByExample(null);
        if(storeList!=null){
            return ServerResponse.getSuccess(storeList);
        }else {
            return ServerResponse.getFail(null);
        }
    }

    @Override
    public ServerResponse getByStoreName(String storeName) {
        StoreExample storeExample = new StoreExample();
        StoreExample.Criteria criteria = storeExample.createCriteria();
        criteria.andStoreNameEqualTo(storeName);
        Store store = storeMapper.selectByExample(storeExample).get(0);
        if(store != null)
            return ServerResponse.getSuccess(store);
        return ServerResponse.getFail(null);
    }

    @Override
    public ServerResponse getById(Integer storeId) {
        Store store = storeMapper.selectByPrimaryKey(storeId);
        if(store!= null)
            return ServerResponse.getSuccess(store);
        return ServerResponse.getFail(null);
    }
    // 根据城市查询店铺
    @Override
    public ServerResponse getStoreByStoreCity(String storeCity) {
        StoreExample storeExample = new StoreExample();
        storeExample.createCriteria().andStoreCityEqualTo(storeCity);
        List<Store> storeList = storeMapper.selectByExample(storeExample);
        if(storeList.size() > 0)
            return ServerResponse.getSuccess(storeList);
        return ServerResponse.getFail(null);
    }

}
